package com.suray.wcs.service.pojo.rgv.rgv.protocol.message;

import com.suray.basic.wcs.utils.typedef.Byte;
import com.suray.basic.wcs.utils.typedef.DWord;
import com.suray.basic.wcs.utils.typedef.Word;
import com.suray.commin.core.utils.SpringContextHolder;
import com.suray.type.ErrorLevel;
import com.suray.wcs.service.enums.CodeType;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.pojo.RgvChargeInfo;
import com.suray.wcs.service.pojo.rgv.rgv.protocol.base.RgvRecMessage;
import com.suray.wcs.service.pojo.rgv.rgv.protocol.util.RgvMessageType;
import com.suray.wcs.service.system.entity.CodeDB;
import com.suray.wcs.service.system.entity.ScadaDB;
import com.suray.wcs.service.system.service.impl.CodeDBServiceImpl;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class RgvRecScadaMessage extends RgvRecMessage {
    private final static CodeDBServiceImpl codeDBService = SpringContextHolder.getBean(CodeDBServiceImpl.class);

    public RgvRecScadaMessage(Rgv rgv) {
        super(rgv, "Rgv返回Scada数据");
        int i;
        baseDatas.add(new Word("头帧", "取值0x02FD"));
        baseDatas.add(new Byte("设备ID", "取值范围：0-255， 小车对应设备号"));
        baseDatas.add(new Byte("life", "0-255"));
        baseDatas.add(new Byte("报文类型", "0:心跳，1：整体任务，2：指令，3：调试指令,5 获取SCADA系统参数指令模式"));
        baseDatas.add(new Word("RunTime", "小车运行时间"));
        baseDatas.add(new Word("DrivingSpeed", "行驶转速"));
        baseDatas.add(new Byte("ObstacleAhead", "小车前方障碍物"));
        baseDatas.add(new Word("DrivingVolt", "行驶驱动电压, fact:0.1V, offset:0"));
        baseDatas.add(new Word("DrivingCurr", "行驶驱动电流, fact:0.1A, offset:0"));
        baseDatas.add(new Word("TrayObstaDis", "托盘障碍物激光雷达距离;显示的是行驶方向所在位置的激光雷达数据    若小车静止时为0"));
        baseDatas.add(new Word("SuroundObstaDis", "四周障碍物激光雷达距离;显示的是行驶方向所在位置的激光雷达数据    若小车静止时为0"));
        baseDatas.add(new Word("HydraulicSpeed", "液s压转速（r）；前四位是正转货反转   后12位代表转速"));
        baseDatas.add(new Byte("HydraOilTemp", "液压油温"));
        baseDatas.add(new Word("HydraDriveVolt", "液压驱动电压, fact:0.1V, offset:0"));
        baseDatas.add(new Word("HydraDriveCurr", "液压驱动电流, fact:0.1A, offset:0"));
        //60节电池电压值
        for (i = 1; i < 61; i++) {
            baseDatas.add(new Word("SingleBatteryVolt" + i, "各节电压, 共有60节，单位10mv"));
        }
        baseDatas.add(new Byte("MinVoltCellNum", "电池单节最低电压节号"));
        baseDatas.add(new Byte("MaxVoltCellNum", "电池单节最高电压节号"));
        baseDatas.add(new Word("MaxVoltDiffer", "最大压差"));
        baseDatas.add(new Word("totalVolt", "总电压"));
        baseDatas.add(new Word("BatteryOpenChargeCurr", "充电电流"));
        baseDatas.add(new Word("BatteryCloseChargeCurr", "放电电流"));
        baseDatas.add(new Byte("leftBatteryEle", "剩余电量"));
        for (i = 1; i < 9; i++) {
            baseDatas.add(new Word("BatteryTemp" + i, "电芯温度,8个温度采集点"));
        }
        baseDatas.add(new Word("BalanResistTemp1", "均衡MOS管温度1"));
        baseDatas.add(new Word("BalanResistTemp2", "均衡MOS管温度2"));
        baseDatas.add(new Word("MOSTemp1", "充放MOS管温度1"));
        baseDatas.add(new Word("MOSTemp2", "充放MOS管温度2"));
        baseDatas.add(new Word("cycleCount", "循环次数"));
        baseDatas.add(new Word("ErrorMsg", "故障信息"));
        baseDatas.add(new DWord("BatteryStaMsg", "电池状态信息"));
        baseDatas.add(new DWord("TravelDistance", "行驶里程数"));
        baseDatas.add(new DWord("TravelDriveErrCount", "行驶驱动器故障次数"));
        baseDatas.add(new DWord("TravelDriveExecCount", "行驶驱动器执行动作次数"));
        baseDatas.add(new DWord("PltCodeScannerStatus", "托盘扫码器状态"));
        baseDatas.add(new DWord("OilDriveExecCount", "换向、托盘动作执行总次数"));
        baseDatas.add(new DWord("OilDriveErrCount", "油泵驱动器故障次数"));
        baseDatas.add(new Word("报文长度", "整条报文的长度"));
        baseDatas.add(new Word("校验位", "CRC（循环冗余校验；低位在前，高位在后），采用crc16_modbus"));
        baseDatas.add(new Word("尾帧", "0x3FC"));
    }


    public Integer getRunTime() {
        return getValue("RunTime");
    }

    public Integer getDrivingSpeed() {
        return getValue("DrivingSpeed");
    }

    public Integer getObstacleAhead() {
        return getValue("ObstacleAhead");
    }

    public Integer getDrivingVolt() {
        return getValue("DrivingVolt");
    }

    public Integer getDrivingCurr() {
        return getValue("DrivingCurr");
    }

    public Integer getTrayObstaDis() {
        return getValue("TrayObstaDis");
    }

    public Integer getSuroundObstaDis() {
        return getValue("SuroundObstaDis");
    }

    public Integer getHydraulicSpeed() {
        return getValue("HydraulicSpeed");
    }

    public Integer getHydraOilTemp() {
        return getValue("HydraOilTemp");
    }

    public Integer getHydraDriveVolt() {
        return getValue("HydraDriveVolt");
    }

    public Integer getHydraDriveCurr() {
        return getValue("HydraDriveCurr");
    }

    //电压
    public Integer getSingleBatteryVolt1() {
        return getValue("SingleBatteryVolt1");
    }

    public Integer getSingleBatteryVolt2() {
        return getValue("SingleBatteryVolt2");
    }

    public Integer getSingleBatteryVolt3() {
        return getValue("SingleBatteryVolt3");
    }

    public Integer getSingleBatteryVolt4() {
        return getValue("SingleBatteryVolt4");
    }

    public Integer getSingleBatteryVolt5() {
        return getValue("SingleBatteryVolt5");
    }

    public Integer getSingleBatteryVolt6() {
        return getValue("SingleBatteryVolt6");
    }

    public Integer getSingleBatteryVolt7() {
        return getValue("SingleBatteryVolt7");
    }

    public Integer getSingleBatteryVolt8() {
        return getValue("SingleBatteryVolt8");
    }

    public Integer getSingleBatteryVolt9() {
        return getValue("SingleBatteryVolt9");
    }

    public Integer getSingleBatteryVolt10() {
        return getValue("SingleBatteryVolt10");
    }

    public Integer getSingleBatteryVolt11() {
        return getValue("SingleBatteryVolt11");
    }

    public Integer getSingleBatteryVolt12() {
        return getValue("SingleBatteryVolt12");
    }

    public Integer getSingleBatteryVolt13() {
        return getValue("SingleBatteryVolt13");
    }

    public Integer getSingleBatteryVolt14() {
        return getValue("SingleBatteryVolt14");
    }

    public Integer getSingleBatteryVolt15() {
        return getValue("SingleBatteryVolt15");
    }

    public Integer getSingleBatteryVolt16() {
        return getValue("SingleBatteryVolt16");
    }

    public Integer getSingleBatteryVolt17() {
        return getValue("SingleBatteryVolt17");
    }

    public Integer getSingleBatteryVolt18() {
        return getValue("SingleBatteryVolt18");
    }

    public Integer getSingleBatteryVolt19() {
        return getValue("SingleBatteryVolt19");
    }

    public Integer getSingleBatteryVolt20() {
        return getValue("SingleBatteryVolt20");
    }

    public Integer getSingleBatteryVolt21() {
        return getValue("SingleBatteryVolt21");
    }

    public Integer getSingleBatteryVolt22() {
        return getValue("SingleBatteryVolt22");
    }

    public Integer getSingleBatteryVolt23() {
        return getValue("SingleBatteryVolt23");
    }

    public Integer getSingleBatteryVolt24() {
        return getValue("SingleBatteryVolt24");
    }

    public Integer getSingleBatteryVolt25() {
        return getValue("SingleBatteryVolt25");
    }

    public Integer getSingleBatteryVolt26() {
        return getValue("SingleBatteryVolt26");
    }

    public Integer getSingleBatteryVolt27() {
        return getValue("SingleBatteryVolt27");
    }

    public Integer getSingleBatteryVolt28() {
        return getValue("SingleBatteryVolt28");
    }

    public Integer getSingleBatteryVolt29() {
        return getValue("SingleBatteryVolt29");
    }

    public Integer getSingleBatteryVolt30() {
        return getValue("SingleBatteryVolt30");
    }

    public Integer getSingleBatteryVolt31() {
        return getValue("SingleBatteryVolt31");
    }

    public Integer getSingleBatteryVolt32() {
        return getValue("SingleBatteryVolt32");
    }

    public Integer getSingleBatteryVolt33() {
        return getValue("SingleBatteryVolt33");
    }

    public Integer getSingleBatteryVolt34() {
        return getValue("SingleBatteryVolt34");
    }

    public Integer getSingleBatteryVolt35() {
        return getValue("SingleBatteryVolt35");
    }

    public Integer getSingleBatteryVolt36() {
        return getValue("SingleBatteryVolt36");
    }

    public Integer getSingleBatteryVolt37() {
        return getValue("SingleBatteryVolt37");
    }

    public Integer getSingleBatteryVolt38() {
        return getValue("SingleBatteryVolt38");
    }

    public Integer getSingleBatteryVolt39() {
        return getValue("SingleBatteryVolt39");
    }

    public Integer getSingleBatteryVolt40() {
        return getValue("SingleBatteryVolt40");
    }

    public Integer getSingleBatteryVolt41() {
        return getValue("SingleBatteryVolt41");
    }

    public Integer getSingleBatteryVolt42() {
        return getValue("SingleBatteryVolt42");
    }

    public Integer getSingleBatteryVolt43() {
        return getValue("SingleBatteryVolt43");
    }

    public Integer getSingleBatteryVolt44() {
        return getValue("SingleBatteryVolt44");
    }

    public Integer getSingleBatteryVolt45() {
        return getValue("SingleBatteryVolt45");
    }

    public Integer getSingleBatteryVolt46() {
        return getValue("SingleBatteryVolt46");
    }

    public Integer getSingleBatteryVolt47() {
        return getValue("SingleBatteryVolt47");
    }

    public Integer getSingleBatteryVolt48() {
        return getValue("SingleBatteryVolt48");
    }

    public Integer getSingleBatteryVolt49() {
        return getValue("SingleBatteryVolt49");
    }

    public Integer getSingleBatteryVolt50() {
        return getValue("SingleBatteryVolt50");
    }

    public Integer getSingleBatteryVolt51() {
        return getValue("SingleBatteryVolt51");
    }

    public Integer getSingleBatteryVolt52() {
        return getValue("SingleBatteryVolt52");
    }

    public Integer getSingleBatteryVolt53() {
        return getValue("SingleBatteryVolt53");
    }

    public Integer getSingleBatteryVolt54() {
        return getValue("SingleBatteryVolt54");
    }

    public Integer getSingleBatteryVolt55() {
        return getValue("SingleBatteryVolt55");
    }

    public Integer getSingleBatteryVolt56() {
        return getValue("SingleBatteryVolt56");
    }

    public Integer getSingleBatteryVolt57() {
        return getValue("SingleBatteryVolt57");
    }

    public Integer getSingleBatteryVolt58() {
        return getValue("SingleBatteryVolt58");
    }

    public Integer getSingleBatteryVolt59() {
        return getValue("SingleBatteryVolt59");
    }

    public Integer getSingleBatteryVolt60() {
        return getValue("SingleBatteryVolt60");
    }

    public Integer getMinVoltCellNum() {
        return getValue("MinVoltCellNum");
    }

    public Integer getMaxVoltCellNum() {
        return getValue("MaxVoltCellNum");
    }

    public Integer getMaxVoltDiffer() {
        return getValue("MaxVoltDiffer");
    }

    public Integer gettotalVolt() {
        return getValue("totalVolt");
    }

    public Integer getBatteryOpenChargeCurr() {
        return getValue("BatteryOpenChargeCurr");
    }

    public Integer getBatteryCloseChargeCurr() {
        return getValue("BatteryCloseChargeCurr");
    }

    public Integer getLeftBatteryEle() {
        return getValue("leftBatteryEle");
    }

    //温度
    public Integer getBatteryTemp1() {
        return getValue("BatteryTemp1");
    }

    public Integer getBatteryTemp2() {
        return getValue("BatteryTemp2");
    }

    public Integer getBatteryTemp3() {
        return getValue("BatteryTemp3");
    }

    public Integer getBatteryTemp4() {
        return getValue("BatteryTemp4");
    }

    public Integer getBatteryTemp5() {
        return getValue("BatteryTemp5");
    }

    public Integer getBatteryTemp6() {
        return getValue("BatteryTemp6");
    }

    public Integer getBatteryTemp7() {
        return getValue("BatteryTemp7");
    }

    public Integer getBatteryTemp8() {
        return getValue("BatteryTemp8");
    }

    public Integer getBalanResistTemp1() {
        return getValue("BalanResistTemp1");
    }

    public Integer getBalanResistTemp2() {
        return getValue("BalanResistTemp2");
    }

    public Integer getMOSTemp1() {
        return getValue("MOSTemp1");
    }

    public Integer getMOSTemp2() {
        return getValue("MOSTemp2");
    }

    public Integer getcycleCount() {
        return getValue("cycleCount");
    }

    public Integer getErrorMsg() {
        return getValue("ErrorMsg");
    }

    public Integer getTravelDistance() {
        return getValue("TravelDistance");
    }

    public Integer getTravelDriveErrCount() {
        return getValue("TravelDriveErrCount");
    }

    public Integer getTravelDriveExecCount() {
        return getValue("TravelDriveExecCount");
    }

    public Integer getPltCodeScannerStatus() {
        return getValue("PltCodeScannerStatus");
    }

    public Integer getOilDriveExecCount() {
        return getValue("OilDriveExecCount");
    }

    public Integer getOilDriveErrCount() {
        return getValue("OilDriveErrCount");
    }


    @Override
    public Integer getMessageLife() {
        return getValue("life");
    }

    @Override
    public Integer getMessageType() {
        return getValue("报文类型");
    }

    public Integer getMessageLength() {
        return getValue("报文长度");
    }

    @Override
    public boolean checkMessage(byte[] recData, RgvMessageType rgvMessageType, Integer sendLife) throws IOException {
        boolean result = super.checkMessage(recData, rgvMessageType, sendLife);

        int messageLength = getMessageLength();
        if (recData.length != messageLength) {
            throw new RuntimeException("解析的报文长度与接收的实际长度不一致:" + Arrays.toString(recData));
        }

        if (result) {
            analyzeMessage();
        }

        return result;
    }

    /**
     * SCADA数据设置
     */
    private void analyzeMessage() {
        Rgv rgv = getRgv();
        ScadaDB scadaDB = new ScadaDB(new RgvChargeInfo());
        scadaDB.setRgvNo(getRgv().getRgvDB().getRgvNo());
        setScadaData(scadaDB);
        rgv.setRgvChargeInfo(scadaDB.getRgvChargeInfo());
        int errorMsg = scadaDB.getRgvChargeInfo().getErrorMsg();
        if (errorMsg != 0) {
            List<CodeDB> codeDBList = codeDBService.getCodeDBsByType(CodeType.BATTERY_BALANCE_ERROR.getValue());
            ErrorLevel errorLevel = ErrorLevel.NON_ERROR;
            for (CodeDB codeDB : codeDBList) {
                if (isBatteryError(errorMsg, codeDB)) {
                    ErrorLevel level = ErrorLevel.parseLevel(codeDB.getCodeLevel());
                    if (level.checkLevel(errorLevel)) {
                        errorLevel = level;
                    }
                }
            }

            if (errorLevel == ErrorLevel.NON_ERROR) {
                recoveryBatteryError(rgv);
            } else {
                rgv.setBatterBalanceError(errorLevel);
            }
        } else {
            recoveryBatteryError(rgv);
        }
    }

    public boolean isBatteryError(int errorCode, CodeDB codeDB) {
        return ((errorCode >> codeDB.getCodeDec()) & 0b1) > 0;
    }

    /**
     * 恢复电池均衡故障
     * @param rgv
     */
    private void recoveryBatteryError(Rgv rgv) {
        rgv.setBatterBalanceError(ErrorLevel.NON_ERROR);
    }


    private void setScadaData(ScadaDB scadaDB) {
        scadaDB.setRunTime(getRunTime());
        scadaDB.setDrivingSpeed(getDrivingSpeed());
        scadaDB.setObstacleAhead(getObstacleAhead());
        scadaDB.setDrivingVolt(getDrivingVolt());
        scadaDB.setDrivingCurr(getDrivingCurr());
        scadaDB.setTrayObstaDis(getTrayObstaDis());
        scadaDB.setSuroundObstaDis(getSuroundObstaDis());
        scadaDB.setHydraulicSpeed(getHydraulicSpeed());
        scadaDB.setHydraOilTemp(getHydraOilTemp());
        scadaDB.setHydraDriveVolt(getDrivingVolt());
        scadaDB.setHydraDriveCurr(getDrivingCurr());
        scadaDB.setHydraDriveVolt(getHydraDriveVolt());
        scadaDB.setHydraDriveCurr(getHydraDriveCurr());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt1(getSingleBatteryVolt1());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt2(getSingleBatteryVolt2());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt3(getSingleBatteryVolt3());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt4(getSingleBatteryVolt4());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt5(getSingleBatteryVolt5());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt6(getSingleBatteryVolt6());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt7(getSingleBatteryVolt7());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt8(getSingleBatteryVolt8());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt9(getSingleBatteryVolt9());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt10(getSingleBatteryVolt10());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt11(getSingleBatteryVolt11());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt12(getSingleBatteryVolt12());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt13(getSingleBatteryVolt13());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt14(getSingleBatteryVolt14());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt15(getSingleBatteryVolt15());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt16(getSingleBatteryVolt16());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt17(getSingleBatteryVolt17());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt18(getSingleBatteryVolt18());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt19(getSingleBatteryVolt19());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt20(getSingleBatteryVolt20());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt21(getSingleBatteryVolt21());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt22(getSingleBatteryVolt22());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt23(getSingleBatteryVolt23());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt24(getSingleBatteryVolt24());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt25(getSingleBatteryVolt25());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt26(getSingleBatteryVolt26());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt27(getSingleBatteryVolt27());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt28(getSingleBatteryVolt28());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt29(getSingleBatteryVolt29());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt30(getSingleBatteryVolt30());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt31(getSingleBatteryVolt31());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt32(getSingleBatteryVolt32());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt33(getSingleBatteryVolt33());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt34(getSingleBatteryVolt34());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt35(getSingleBatteryVolt35());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt36(getSingleBatteryVolt36());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt37(getSingleBatteryVolt37());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt38(getSingleBatteryVolt38());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt39(getSingleBatteryVolt39());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt40(getSingleBatteryVolt40());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt41(getSingleBatteryVolt41());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt42(getSingleBatteryVolt42());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt43(getSingleBatteryVolt43());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt44(getSingleBatteryVolt44());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt45(getSingleBatteryVolt45());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt46(getSingleBatteryVolt46());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt47(getSingleBatteryVolt47());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt48(getSingleBatteryVolt48());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt49(getSingleBatteryVolt49());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt50(getSingleBatteryVolt50());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt51(getSingleBatteryVolt51());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt52(getSingleBatteryVolt52());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt53(getSingleBatteryVolt53());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt54(getSingleBatteryVolt54());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt55(getSingleBatteryVolt55());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt56(getSingleBatteryVolt56());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt57(getSingleBatteryVolt57());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt58(getSingleBatteryVolt58());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt59(getSingleBatteryVolt59());
        scadaDB.getRgvChargeInfo().setSingleBatteryVolt60(getSingleBatteryVolt60());
        scadaDB.getRgvChargeInfo().setMinVoltCellNum(getMinVoltCellNum());
        scadaDB.getRgvChargeInfo().setMaxVoltCellNum(getMaxVoltCellNum());
        scadaDB.getRgvChargeInfo().setMaxVoltDiffer(getMaxVoltDiffer() * 10);
        scadaDB.getRgvChargeInfo().setTotalVolt((float) gettotalVolt() / 100);
        scadaDB.getRgvChargeInfo().setBatteryOpenChargeCurr((float) getBatteryOpenChargeCurr() / 100);
        scadaDB.getRgvChargeInfo().setBatteryCloseChargeCurr((float) getBatteryCloseChargeCurr() / 100);
        scadaDB.getRgvChargeInfo().setLeftBatteryEle(getLeftBatteryEle());
        scadaDB.getRgvChargeInfo().setBatteryTemp1(getBatteryTemp1());
        scadaDB.getRgvChargeInfo().setBatteryTemp2(getBatteryTemp2());
        scadaDB.getRgvChargeInfo().setBatteryTemp3(getBatteryTemp3());
        scadaDB.getRgvChargeInfo().setBatteryTemp4(getBatteryTemp4());
        scadaDB.getRgvChargeInfo().setBatteryTemp5(getBatteryTemp5());
        scadaDB.getRgvChargeInfo().setBatteryTemp6(getBatteryTemp6());
        scadaDB.getRgvChargeInfo().setBatteryTemp7(getBatteryTemp7());
        scadaDB.getRgvChargeInfo().setBatteryTemp8(getBatteryTemp8());
        scadaDB.getRgvChargeInfo().setBalanResistTemp1(getBalanResistTemp1());
        scadaDB.getRgvChargeInfo().setBalanResistTemp2(getBalanResistTemp2());
        scadaDB.getRgvChargeInfo().setMosTemp1(getMOSTemp1());
        scadaDB.getRgvChargeInfo().setMosTemp2(getMOSTemp2());
        scadaDB.getRgvChargeInfo().setCycleCount(getcycleCount());
        scadaDB.getRgvChargeInfo().setErrorMsg(getErrorMsg());

        getRgv().addOdo(getTravelDistance());
        getRgv().addAct(getOilDriveExecCount());

        scadaDB.setTravelDistance(getRgv().getOdo());
        scadaDB.setTravelDriveErrCount(getTravelDriveErrCount());
        scadaDB.setTravelDriveExecCount(getTravelDriveExecCount());
        scadaDB.setPltCodeScannerStatus(getPltCodeScannerStatus());
        scadaDB.setOilDriveExecCount(getRgv().getAct());
        scadaDB.setOilDriveErrCount(getOilDriveErrCount());

    }

    private static byte[] getData() {
        String str = "02 FD 01 2E 05 00 79 00 00 94 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 13 0C 17 0C 1A 0C 88 0C 8B 0C 8B 0C 92 0C 92 0C 93 0C 94 0C 9A 0C B4 0C C1 0C C1 0C C1 0C C2 0C C2 0C C2 0C C2 0C C3 0C C3 0C C3 0C C3 0C C3 0C C3 0C C4 0C C4 0C C4 0C C4 0C C4 0C C5 0C C5 0C C5 0C C5 0C C5 0C C5 0C C5 0C C5 0C C5 0C C6 0C C6 0C C6 0C C6 0C C6 0C C6 0C C6 0C C7 0C C7 0C C7 0C C7 0C C7 0C C7 0C C7 0C C8 0C C8 0C C8 0C C8 0C CA 0C D2 0C D2 27 06 00 08 2F 2E 00 00 00 33 11 00 18 00 18 00 18 00 18 00 18 00 18 00 19 00 1A 00 2B 00 29 00 2C 00 29 00 01 00 00 00 BE C5 AB 03 FC ";
        String[] strs = str.split(" ");

        byte[] data = new byte[strs.length];

        for (int i = 0; i < strs.length; i++) {
            data[i] = Integer.valueOf(strs[i], 16).byteValue();
        }

        return data;
    }

    public static void main(String[] args) {
        RgvRecScadaMessage rgvRecScadaMessage = new RgvRecScadaMessage(null);

        byte[] data = getData();

        try {
            rgvRecScadaMessage.checkMessage(data, RgvMessageType.RGV_SCADA_MESSAGE, 46);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
